<!--
 * @Author: WangShuai 1830773767@qq.com
 * @Date: 2025-06-23 22:37:57
 * @LastEditors: WangShuai 1830773767@qq.com
 * @LastEditTime: 2025-06-23 23:11:19
 * @FilePath: \shangyitong\src\components\countdown\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
 <div>
    <span>获取验证码({{time}}s)</span>
 </div>
</template>

<script setup lang="ts">
import {ref,watch,nextTick} from 'vue'
let $emit = defineEmits(['getFlag'])
//接收父组件传递过来的props数据flag
 let props = defineProps({
    flag:{
        type:Boolean,
        default:false
    }
 })
 //监听倒计时时间
 let time = ref<number>(5)
 watch(()=>props.flag,()=>{
    nextTick(()=>{
      let timer = setInterval(()=>{
            time.value-- 
            if(time.value==0){
                //清除定时器
                clearInterval(timer)
                $emit("getFlag",false)
            }
        },1000)
    })
 },{immediate:true})
 
</script>

<style lang="scss" scoped>
  
</style>